package com.thy.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hospital.common.base.ThreadAttributes;
import com.hospital.common.dto.audit.module.DeleteContentDto;
import com.hospital.common.pojo.TPostContent;
import com.hospital.common.utils.ThreadLocalUtils;
import com.thy.aop.LogAction;
import com.thy.mapper.TPostContentMapper;
import com.thy.service.TPostContentService;
import com.thy.utils.AuitLogUtil;
import com.thy.utils.MessageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 帖子内容表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-09-26
 */
@Service
public class TPostContentServiceImpl extends ServiceImpl<TPostContentMapper, TPostContent> implements TPostContentService {
    @Autowired
    private TPostContentMapper tPostContentMapper;
    @Override
    public void deleteContent(DeleteContentDto deleteContentDto) {
        ThreadAttributes threadAttributes = ThreadLocalUtils.get();
        Long userId = threadAttributes.getUserId();
        tPostContentMapper.deleteContent(deleteContentDto,userId);
        //日志记录
        AuitLogUtil.log(userId, LogAction.CONTENT_DELETED.getId(),deleteContentDto.getOpId(),AuitLogUtil.getRole(deleteContentDto.getOpId()).longValue());
        if (deleteContentDto.getOpId().longValue() != userId.longValue()){
            MessageUtil.sendMessage(userId,deleteContentDto.getOpId(),"您的帖子包含违规信息,已被管理员删除！");
        }
    }
}
